package com.lzc.controller;

import com.lzc.pojo.vo.CommentGetVo;
import com.lzc.pojo.vo.CommentPutVo;
import com.lzc.pojo.vo.Result;
import com.lzc.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/im/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 查询当前文章的评论
     * @param vo 参数
     * @return
     */
    @GetMapping("/get/all")
    public Result findAllComments(@RequestBody CommentGetVo vo){
         return commentService.findAllComments(vo.getArticleId(),vo.getPage(),vo.getSize());
    }

    /**
     * 查询当前文章的评论总数
     * @param articleId 当前文章id
     * @return
     */
    @GetMapping("/get/count/{articleId}")
    public Result findCount(@PathVariable("articleId") Long articleId){
        return commentService.findCount(articleId);
    }

    /**
     * 新增评论
     * @param commentPutVo 评论信息
     * @return
     */
    @PostMapping("/add")
    public Result addComment(@RequestBody CommentPutVo commentPutVo){
        return commentService.addComment(commentPutVo);
    }
}
